package cn.xinfei.xdecision.common.utils.enums.enginex;

import cn.xinfei.xdecision.common.utils.exception.ApiException;
import cn.xinfei.xdecision.common.utils.exception.enums.ErrorCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 组件类型枚举
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum NodeTypeEnum {
    /**
     * 开始节点
     */
    START(1, "start", "开始"),
    /**
     * 结束节点
     */
    END(99, "end", "结束"),
    /**
     * 规则库
     */
    RULE_BASE(2, "ruleBase", "规则库"),
    /**
     * 分组节点
     */
    CLASSIFY(3, "classify", "分组"),
    /**
     * 评分卡节点
     */
    SCORECARD(4, "scorecard", "评分卡"),
    /**
     * 分流节点
     */
    SANDBOX(7, "sandbox", "分流"),
    /**
     * 决策选项节点
     */
    DECISION(9, "decision", "决策选项"),
    /**
     * 子引擎
     */
    CHILD_ENGINE(14, "childEngine", "子引擎"),
    /**
     * 决策表
     */
    DECISION_TABLES(16, "decisionTable", "决策表"),
    /**
     * 决策树
     */
    DECISION_TREE(17, "decisionTree", "决策树"),
    /**
     * 并行节点
     */
    PARALLEL(19, "parallel", "并行"),
    /**
     * 聚合节点
     */
    AGGREGATION(20, "aggregation", "聚合"),
    /**
     * 冠军挑战节点
     */
    CHAMPION_CHALLENGE(21, "championChallenge", "冠军挑战"),
    /**
     * 人行征信
     */
    CREDIT_REPORT(22, "creditReport", "人行征信"),
    /**
     * 决策流
     */
    DECISION_FLOW(-1, "decisionFlow", "决策流"),
    /**
     * 动作节点
     */
    ACTION(23, "action", "动作");

    private final int code;
    private final String type;

    private final String message;

    public static NodeTypeEnum adapad(String type) {
        for (NodeTypeEnum nodeTypeEnum : NodeTypeEnum.values()) {
            if (nodeTypeEnum.getType().equals(type)) {
                return nodeTypeEnum;
            }
        }
        log.error("NodeTypeEnum 参数异常 type={}", type);
        throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), ErrorCodeEnum.PARAMS_EXCEPTION.getMessage());
    }
}
